<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">
<title>云盘首页</title>
<jsp:include page="/public/pub.jsp"></jsp:include>
</head>
<body>
	<jsp:include page="/public/top.jsp"></jsp:include>
	<div class="main-container" id="main-container">
		<script type="text/javascript">
			try {
				ace.settings.check('main-container', 'fixed')//主界面展开显示
			} catch (e) {
			}
		</script>
		<div class="main-container-inner">
			<a class="menu-toggler" id="menu-toggler" href="#"> <span class="menu-text"></span>
			</a>
			<jsp:include page="/public/left.jsp"></jsp:include>
			<div class="main-content">
				<div class="breadcrumbs" id="breadcrumbs">
					<script type="text/javascript">
						try {
							ace.settings.check('breadcrumbs', 'fixed')//展开breadcrumbs
						} catch (e) {
						}
					</script>
					<div>
						<ul class="breadcrumb">
							<li><i class="icon-home home-icon"></i> <a href="#">首页</a></li>
							<li class="active">文档</li>
						</ul>
					</div>
					<ul class="breadcrumb">
						<input type="button" class="button darkblue" value="删除" onclick="deldir()" />
						<input type="button" class="button teal" value="分享" onclick="share()" />
					</ul>
					<!-- .breadcrumb -->
				</div>
				<div class="page-content">
					<script type="text/javascript">
						function share() {//分享
							var ids = [];
							$("#listdir input[type=checkbox]").each(function() {
								if (this.checked == true) {
									ids.push(this.value);
								}
							});
							if (ids.length > 0) {
								$.post('${pageContext.request.contextPath}/cloud/share.do', {
									dir : ids.join(','),
									link : this.location.href
								});
								alert("分享成功!");
								location.reload();
							} else {
								alert("你没有选择");
							}
						}

						function selectBox() {//选择对应的checkbox
							$("#listdir input[type=checkbox]").each(function() {
								if (this.checked == true) {
									this.checked = false;
								} else {
									this.checked = true;
								}
							});
						}
						function deldir() {//删除所选的文件或文件夹
							var dir;
							var ids = [];
							$("#listdir input[type=checkbox]").each(function() {
								if (this.checked == true) {
									ids.push(this.value);
									dir = this.name;
								}
							});
							if (ids.length > 0) {
								layer.confirm('删除提醒', function(index) {
									$.post('${pageContext.request.contextPath}/cloud/delete.do', {
										ids : ids.join(','),
										dir : dir
									}, function(j) {
										if (j.success) {
											location.reload();
										} else {
											alert(json.msg);
										}
									}, 'json');
								});
							} else {
								layer.msg('你没有选择', 2, -1);
							}
						}
						$(document).ready(function() {//文件多选框
							$('table th input:checkbox').on('click', function() {
								var that = this;
								$(this).closest('table').find('tr > td:first-child input:checkbox').each(function() {
									this.checked = that.checked;
									$(this).closest('tr').toggleClass('selected');
								});

							});
						});
						function editName(index) {//编辑文件名
							$("#edit01" + index).hide();
							$("#edit02" + index).show();
						}
						function removeBut(index) {//取消编辑
							$("#edit02" + index).hide();
							$("#edit01" + index).show();
						}
						function renameBut(dir, index, name, type) {//重命名文件
							var newname = $.trim($("#rename" + index).val());
							if (newname == null || newname == '') {
								alert("请输入名称");
								return false;
							}
							$.post('${pageContext.request.contextPath}/cloud/rename.do', {
								dir : dir,
								name : name,
								rename : newname,
								type : type
							}, function(j) {
								if (j.success) {
									location.reload();
								} else {
									alert(json.msg);
								}
							}, 'json');
						}
						function viewName(index, name) {//在线浏览文件
							$.layer({
								type : 2,
								border : [ 0 ],
								title : false,
								closeBtn : [ 0, true ],
								iframe : {
									src : 'cloud/view.do?dir=' + index + '&name=' + name
								},
								area : [ '950px', '630px' ]
							});
						}
						function downName(name, dir) {//下载文件
							$.layer({
								type : 2,
								border : [ 0 ],
								title : false,
								closeBtn : [ 0, true ],
								iframe : {
									src : 'cloud/download.do?dir=' + dir + '&name=' + name
								},
								area : [ '0px', '0px' ]
							});
						}
					</script>
					<!-- /.page-header -->
					<div class="row">
						<div class="col-xs-12">
							<div id="dialog-confirm" class="hide">
								<p class="bigger-110 bolder center grey">
									<i class="icon-hand-right blue bigger-120"></i> 你确定要删除么？
								</p>
							</div>
							<!-- PAGE CONTENT BEGINS -->
							<table id="sample-table-1" class="table table-striped table-bordered table-hover">
								<thead>
									<tr>
										<th class="center"><label><input type="checkbox" class="ace" autocomplete="off" /> <span class="lbl"></span> </label></th>
										<th class="center">文件名</th>
										<th class="center">大小</th>
										<th class="center">修改日期</th>
										<th class="center">所在目录</th>
										<th class="center">操作</th>
									</tr>
								</thead>
								<tbody id="listdir">
									<c:forEach items="${fstxt}" var="entry" varStatus="sta">
										<tr class="center">
											<td><label><input type="checkbox" class="ace" value="${entry.name}" name="${entry.namep}" autocomplete="off" /> <span class="lbl"></span> </label></td>
											<td><div id="edit01${sta.index}">${entry.name}</div>
												<div id="edit02${sta.index}" class="col-xs-6 col-sm-4" style="display: none">
													<div class="input-group">
														<input type="text" id="rename${sta.index}" name="name" class="form-control"> <span class="input-group-btn">
															<button class="btn btn-purple btn-sm" onclick="renameBut('${entry.namep}',${sta.index},'${entry.name}','${entry.type}')" type="button" title="提交">
																<i class="icon-ok bigger-110"></i>
															</button>
															<button class="btn btn-purple btn-sm" onclick="removeBut(${sta.index})" type="button" title="取消">
																<i class="icon-remove bigger-110"></i>
															</button>
														</span>
													</div>
												</div></td>
											<td>${entry.size}</td>
											<td>${entry.date}</td>
											<td><a href="cloud/list.do?name=${entry.namep}">${entry.namep}</a></td>
											<td>
												<button class="btn btn-xs btn-info" onclick="editName(${sta.index})" title="重命名">
													<i class="icon-edit bigger-120"></i>
												</button> <c:if test="${entry.viewflag=='txt'}">
													<button class="btn btn-xs btn-info" onclick="viewName('${entry.namep}','${entry.name}')" title="浏览">
														<i class="icon-eye-open bigger-120"></i>
													</button>
												</c:if>
												<button class="btn btn-xs btn-info" onclick="downName('${entry.name}','${entry.namep}')" title="下载">
													<i class="icon-cloud-download bigger-120"></i>
												</button>
											</td>
										</tr>
									</c:forEach>
								</tbody>
							</table>
							<!-- PAGE CONTENT ENDS -->
						</div>
						<!-- /.col -->
					</div>
					<!-- /.row -->
				</div>
				<!-- /.page-content -->
			</div>
			<!-- /.main-content -->
			<jsp:include page="/public/container.jsp"></jsp:include>
		</div>
		<!-- /.main-container-inner -->
		<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse"> <i class="icon-double-angle-up icon-only bigger-110"></i>
		</a>
	</div>
	<!-- /.main-container -->
	<script type="text/javascript">
		function search() {//搜索
			var search = $("#nav-search-input").val();
			if (search != "") {
				$.post('${pageContext.request.contextPath}/cloud/searchlist.do', {
					searchName : search,
				}, function(data) {
					window.location.href = "${pageContext.request.contextPath}/cloud/search.jsp";
				});
			} else {
				alert("请输入搜索内容!")
			}
		}
		jQuery(function($) {
			$('#tasks').sortable({
				opacity : 0.8,
				revert : true,
				forceHelperSize : true,
				placeholder : 'draggable-placeholder',
				forcePlaceholderSize : true,
				tolerance : 'pointer',
				stop : function(event, ui) {//just for Chrome!!!! so that dropdowns on items don't appear below other items after being moved
					$(ui.item).css('z-index', 'auto');
				}
			});
			$('#tasks').disableSelection();
			$('#tasks input:checkbox').removeAttr('checked').on('click', function() {
				if (this.checked)
					$(this).closest('li').addClass('selected');
				else
					$(this).closest('li').removeClass('selected');
			});
		})
	</script>
</body>
</html>
